/*
 * jQuery Form Plugin
 * version: 2.01 (10/31/2007)
 * @requires jQuery v1.1 or later
 *
 * Examples at: http://malsup.com/jquery/form/
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id$
 */
 (function($) {
/**
 * ajaxSubmit() provides a mechanism for submitting an HTML form using AJAX.
 *
 * ajaxSubmit accepts a single argument which can be either a success callback function
 * or an options Object.  If a function is provided it will be invoked upon successful
 * completion of the submit and will be passed the response from the server.
 * If an options Object is provided, the following attributes are supported:
 *
 *  target:   Identifies the element(s) in the page to be updated with the server response.
 *            This value may be specified as a jQuery selection string, a jQuery object,
 *            or a DOM element.
 *            default value: null
 *
 *  url:      URL to which the form data will be submitted.
 *            default value: value of form's 'action' attribute
 *
 *  type:     The method in which the form data should be submitted, 'GET' or 'POST'.
 *            default value: value of form's 'method' attribute (or 'GET' if none found)
 *
 *  data:     Additional data to add to the request, specified as key/value pairs (see $.ajax).
 *
 *  beforeSubmit:  Callback method to be invoked before the form is submitted.
 *            default value: null
 *
 *  success:  Callback method to be invoked after the form has been successfully submitted
 *            and the response has been returned from the server
 *            default value: null
 *
 *  dataType: Expected dataType of the response.  One of: null, 'xml', 'script', or 'json'
 *            default value: null
 *
 *  semantic: Boolean flag indicating whether data must be submitted in semantic order (slower).
 *            default value: false
 *
 *  resetForm: Boolean flag indicating whether the form should be reset if the submit is successful
 *
 *  clearForm: Boolean flag indicating whether the form should be cleared if the submit is successful
 *
 *
 * The 'beforeSubmit' callback can be provided as a hook for running pre-submit logic or for
 * validating the form data.  If the 'beforeSubmit' callback returns false then the form will
 * not be submitted. The 'beforeSubmit' callback is invoked with three arguments: the form data
 * in array format, the jQuery object, and the options object passed into ajaxSubmit.
 * The form data array takes the following form:
 *
 *     [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
 *
 * If a 'success' callback method is provided it is invoked after the response has been returned
 * from the server.  It is passed the responseText or responseXML value (depending on dataType).
 * See jQuery.ajax for further details.
 *
 *
 * The dataType option provides a means for specifying how the server response should be handled.
 * This maps directly to the jQuery.httpData method.  The following values are supported:
 *
 *      'xml':    if dataType == 'xml' the server response is treated as XML and the 'success'
 *                   callback method, if specified, will be passed the responseXML value
 *      'json':   if dataType == 'json' the server response will be evaluted and passed to
 *                   the 'success' callback, if specified
 *      'script': if dataType == 'script' the server response is evaluated in the global context
 *
 *
 * Note that it does not make sense to use both the 'target' and 'dataType' options.  If both
 * are provided the target will be ignored.
 *
 * The semantic argument can be used to force form serialization in semantic order.
 * This is normally true anyway, unless the form contains input elements of type='image'.
 * If your form must be submitted with name/value pairs in semantic order and your form
 * contains an input of type='image" then pass true for this arg, otherwise pass false
 * (or nothing) to avoid the overhead for this logic.
 *
 *
 * When used on its own, ajaxSubmit() is typically bound to a form's submit event like this:
 *
 * $("#form-id").submit(function() {
 *     $(this).ajaxSubmit(options);
 *     return false; // cancel conventional submit
 * });
 *
 * When using ajaxForm(), however, this is done for you.
 *
 * @example
 * $('#myForm').ajaxSubmit(function(data) {
 *     alert('Form submit succeeded! Server returned: ' + data);
 * });
 * @desc Submit form and alert server response
 *
 *
 * @example
 * var options = {
 *     target: '#myTargetDiv'
 * };
 * $('#myForm').ajaxSubmit(options);
 * @desc Submit form and update page element with server response
 *
 *
 * @example
 * var options = {
 *     success: function(responseText) {
 *         alert(responseText);
 *     }
 * };
 * $('#myForm').ajaxSubmit(options);
 * @desc Submit form and alert the server response
 *
 *
 * @example
 * var options = {
 *     beforeSubmit: function(formArray, jqForm) {
 *         if (formArray.length == 0) {
 *             alert('Please enter data.');
 *             return false;
 *         }
 *     }
 * };
 * $('#myForm').ajaxSubmit(options);
 * @desc Pre-submit validation which aborts the submit operation if form data is empty
 *
 *
 * @example
 * var options = {
 *     url: myJsonUrl.php,
 *     dataType: 'json',
 *     success: function(data) {
 *        // 'data' is an object representing the the evaluated json data
 *     }
 * };
 * $('#myForm').ajaxSubmit(options);
 * @desc json data returned and evaluated
 *
 *
 * @example
 * var options = {
 *     url: myXmlUrl.php,
 *     dataType: 'xml',
 *     success: function(responseXML) {
 *        // responseXML is XML document object
 *        var data = $('myElement', responseXML).text();
 *     }
 * };
 * $('#myForm').ajaxSubmit(options);
 * @desc XML data returned from server
 *
 *
 * @example
 * var options = {
 *     resetForm: true
 * };
 * $('#myForm').ajaxSubmit(options);
 * @desc submit form and reset it if successful
 *
 * @example
 * $('#myForm).submit(function() {
 *    $(this).ajaxSubmit();
 *    return false;
 * });
 * @desc Bind form's submit event to use ajaxSubmit
 *
 *
 * @name ajaxSubmit
 * @type jQuery
 * @param options  object literal containing options which control the form submission process
 * @cat Plugins/Form
 * @return jQuery
 */
$.fn.ajaxSubmit = function(options) {
    if (typeof options == 'function')
        options = { success: options };

    options = $.extend({
        url:  this.attr('action') || window.location.toString(),
        type: this.attr('method') || 'GET'
    }, options || {});

    // hook for manipulating the form data before it is extracted;
    // convenient for use with rich editors like tinyMCE or FCKEditor
    var veto = {};
    $.event.trigger('form.pre.serialize', [this, options, veto]);
    if (veto.veto) return this;

    var a = this.formToArray(options.semantic);
	if (options.data) {
	    for (var n in options.data)
	        a.push( { name: n, value: options.data[n] } );
	}

    // give pre-submit callback an opportunity to abort the submit
    if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) return this;

    // fire vetoable 'validate' event
    $.event.trigger('form.submit.validate', [a, this, options, veto]);
    if (veto.veto) return this;

    var q = $.param(a);//.replace(/%20/g,'+');

    if (options.type.toUpperCase() == 'GET') {
        options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
        options.data = null;  // data is null for 'get'
    }
    else
        options.data = q; // data is the query string for 'post'

    var $form = this, callbacks = [];
    if (options.resetForm) callbacks.push(function() { $form.resetForm(); });
    if (options.clearForm) callbacks.push(function() { $form.clearForm(); });

    // perform a load on the target only if dataType is not provided
    if (!options.dataType && options.target) {
        var oldSuccess = options.success || function(){};
        callbacks.push(function(data) {
            if (this.evalScripts)
                $(options.target).attr("innerHTML", data).evalScripts().each(oldSuccess, arguments);
            else // jQuery v1.1.4
                $(options.target).html(data).each(oldSuccess, arguments);
        });
    }
    else if (options.success)
        callbacks.push(options.success);

    options.success = function(data, status) {
        for (var i=0, max=callbacks.length; i < max; i++)
            callbacks[i](data, status, $form);
    };

    // are there files to upload?
    var files = $('input:file', this).fieldValue();
    var found = false;
    for (var j=0; j < files.length; j++)
        if (files[j])
            found = true;

    // options.iframe allows user to force iframe mode
   if (options.iframe || found) { 
       // hack to fix Safari hang (thanks to Tim Molendijk for this)
       // see:  http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
       if ($.browser.safari && options.closeKeepAlive)
           $.get(options.closeKeepAlive, fileUpload);
       else
           fileUpload();
       }
   else
       $.ajax(options);

    // fire 'notify' event
    $.event.trigger('form.submit.notify', [this, options]);
    return this;


    // private function for handling file uploads (hat tip to YAHOO!)
    function fileUpload() {
        var form = $form[0];
        var opts = $.extend({}, $.ajaxSettings, options);

        var id = 'jqFormIO' + $.fn.ajaxSubmit.counter++;
        var $io = $('<iframe id="' + id + '" name="' + id + '" />');
        var io = $io[0];
        var op8 = $.browser.opera && window.opera.version() < 9;
        if ($.browser.msie || op8) io.src = 'javascript:false;document.write("");';
        $io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });

        var xhr = { // mock object
            responseText: null,
            responseXML: null,
            status: 0,
            statusText: 'n/a',
            getAllResponseHeaders: function() {},
            getResponseHeader: function() {},
            setRequestHeader: function() {}
        };

        var g = opts.global;
        // trigger ajax global events so that activity/block indicators work like normal
        if (g && ! $.active++) $.event.trigger("ajaxStart");
        if (g) $.event.trigger("ajaxSend", [xhr, opts]);

        var cbInvoked = 0;
        var timedOut = 0;

        // take a breath so that pending repaints get some cpu time before the upload starts
        setTimeout(function() {
            $io.appendTo('body');
            // jQuery's event binding doesn't work for iframe events in IE
            io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);

            // make sure form attrs are set
            var encAttr = form.encoding ? 'encoding' : 'enctype';
            var t = $form.attr('target');
            $form.attr({
                target:   id,
                method:  'POST',
                action:   opts.url
            });
            form[encAttr] = 'multipart/form-data';

            // support timout
            if (opts.timeout)
                setTimeout(function() { timedOut = true; cb(); }, opts.timeout);

            form.submit();
            $form.attr('target', t); // reset target
        }, 10);

        function cb() {
            if (cbInvoked++) return;

            io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);

            var ok = true;
            try {
                if (timedOut) throw 'timeout';
                // extract the server response from the iframe
                var data, doc;
                doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
                xhr.responseText = doc.body ? doc.body.innerHTML : null;
                xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;

                if (opts.dataType == 'json' || opts.dataType == 'script') {
                    var ta = doc.getElementsByTagName('textarea')[0];
                    data = ta ? ta.value : xhr.responseText;
                    if (opts.dataType == 'json')
                        eval("data = " + data);
                    else
                        $.globalEval(data);
                }
                else if (opts.dataType == 'xml') {
                    data = xhr.responseXML;
                    if (!data && xhr.responseText != null)
                        data = toXml(xhr.responseText);
                }
                else {
                    data = xhr.responseText;
                }
            }
            catch(e){
                ok = false;
                $.handleError(opts, xhr, 'error', e);
            }

            // ordering of these callbacks/triggers is odd, but that's how $.ajax does it
            if (ok) {
                opts.success(data, 'success');
                if (g) $.event.trigger("ajaxSuccess", [xhr, opts]);
            }
            if (g) $.event.trigger("ajaxComplete", [xhr, opts]);
            if (g && ! --$.active) $.event.trigger("ajaxStop");
            if (opts.complete) opts.complete(xhr, ok ? 'success' : 'error');

            // clean up
            setTimeout(function() {
                $io.remove();
                xhr.responseXML = null;
            }, 100);
        };

        function toXml(s, doc) {
            if (window.ActiveXObject) {
                doc = new ActiveXObject('Microsoft.XMLDOM');
                doc.async = 'false';
                doc.loadXML(s);
            }
            else
                doc = (new DOMParser()).parseFromString(s, 'text/xml');
            return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
        };
    };
};
$.fn.ajaxSubmit.counter = 0; // used to create unique iframe ids

/**
 * ajaxForm() provides a mechanism for fully automating form submission.
 *
 * The advantages of using this method instead of ajaxSubmit() are:
 *
 * 1: This method will include coordinates for <input type="image" /> elements (if the element
 *    is used to submit the form).
 * 2. This method will include the submit element's name/value data (for the element that was
 *    used to submit the form).
 * 3. This method binds the submit() method to the form for you.
 *
 * Note that for accurate x/y coordinates of image submit elements in all browsers
 * you need to also use the "dimensions" plugin (this method will auto-detect its presence).
 *
 * The options argument for ajaxForm works exactly as it does for ajaxSubmit.  ajaxForm merely
 * passes the options argument along after properly binding events for submit elements and
 * the form itself.  See ajaxSubmit for a full description of the options argument.
 *
 *
 * @example
 * var options = {
 *     target: '#myTargetDiv'
 * };
 * $('#myForm').ajaxSForm(options);
 * @desc Bind form's submit event so that 'myTargetDiv' is updated with the server response
 *       when the form is submitted.
 *
 *
 * @example
 * var options = {
 *     success: function(responseText) {
 *         alert(responseText);
 *     }
 * };
 * $('#myForm').ajaxSubmit(options);
 * @desc Bind form's submit event so that server response is alerted after the form is submitted.
 *
 *
 * @example
 * var options = {
 *     beforeSubmit: function(formArray, jqForm) {
 *         if (formArray.length == 0) {
 *             alert('Please enter data.');
 *             return false;
 *         }
 *     }
 * };
 * $('#myForm').ajaxSubmit(options);
 * @desc Bind form's submit event so that pre-submit callback is invoked before the form
 *       is submitted.
 *
 *
 * @name   ajaxForm
 * @param  options  object literal containing options which control the form submission process
 * @return jQuery
 * @cat    Plugins/Form
 * @type   jQuery
 */
$.fn.ajaxForm = function(options) {
    return this.ajaxFormUnbind().submit(submitHandler).each(function() {
        // store options in hash
        this.formPluginId = $.fn.ajaxForm.counter++;
        $.fn.ajaxForm.optionHash[this.formPluginId] = options;
        $(":submit,input:image", this).click(clickHandler);
    });
};

$.fn.ajaxForm.counter = 1;
$.fn.ajaxForm.optionHash = {};

function clickHandler(e) {
    var $form = this.form;
    $form.clk = this;
    if (this.type == 'image') {
        if (e.offsetX != undefined) {
            $form.clk_x = e.offsetX;
            $form.clk_y = e.offsetY;
        } else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
            var offset = $(this).offset();
            $form.clk_x = e.pageX - offset.left;
            $form.clk_y = e.pageY - offset.top;
        } else {
            $form.clk_x = e.pageX - this.offsetLeft;
            $form.clk_y = e.pageY - this.offsetTop;
        }
    }
    // clear form vars
    setTimeout(function() { $form.clk = $form.clk_x = $form.clk_y = null; }, 10);
};

function submitHandler() {
    // retrieve options from hash
    var id = this.formPluginId;
    var options = $.fn.ajaxForm.optionHash[id];
    $(this).ajaxSubmit(options);
    return false;
};

/**
 * ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
 *
 * @name   ajaxFormUnbind
 * @return jQuery
 * @cat    Plugins/Form
 * @type   jQuery
 */
$.fn.ajaxFormUnbind = function() {
    this.unbind('submit', submitHandler);
    return this.each(function() {
        $(":submit,input:image", this).unbind('click', clickHandler);
    });

};

/**
 * formToArray() gathers form element data into an array of objects that can
 * be passed to any of the following ajax functions: $.get, $.post, or load.
 * Each object in the array has both a 'name' and 'value' property.  An example of
 * an array for a simple login form might be:
 *
 * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
 *
 * It is this array that is passed to pre-submit callback functions provided to the
 * ajaxSubmit() and ajaxForm() methods.
 *
 * The semantic argument can be used to force form serialization in semantic order.
 * This is normally true anyway, unless the form contains input elements of type='image'.
 * If your form must be submitted with name/value pairs in semantic order and your form
 * contains an input of type='image" then pass true for this arg, otherwise pass false
 * (or nothing) to avoid the overhead for this logic.
 *
 * @example var data = $("#myForm").formToArray();
 * $.post( "myscript.cgi", data );
 * @desc Collect all the data from a form and submit it to the server.
 *
 * @name formToArray
 * @param semantic true if serialization must maintain strict semantic ordering of elements (slower)
 * @type Array<Object>
 * @cat Plugins/Form
 */
$.fn.formToArray = function(semantic) {
    var a = [];
    if (this.length == 0) return a;

    var form = this[0];
    var els = semantic ? form.getElementsByTagName('*') : form.elements;
    if (!els) return a;
    for(var i=0, max=els.length; i < max; i++) {
        var el = els[i];
        var n = el.name;
        if (!n) continue;

        if (semantic && form.clk && el.type == "image") {
            // handle image inputs on the fly when semantic == true
            if(!el.disabled && form.clk == el)
                a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
            continue;
        }

        var v = $.fieldValue(el, true);
        if (v && v.constructor == Array) {
            for(var j=0, jmax=v.length; j < jmax; j++)
                a.push({name: n, value: v[j]});
        }
        else if (v !== null && typeof v != 'undefined')
            a.push({name: n, value: v});
    }

    if (!semantic && form.clk) {
        // input type=='image' are not found in elements array! handle them here
        var inputs = form.getElementsByTagName("input");
        for(var i=0, max=inputs.length; i < max; i++) {
            var input = inputs[i];
            var n = input.name;
            if(n && !input.disabled && input.type == "image" && form.clk == input)
                a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
        }
    }
    return a;
};


/**
 * Serializes form data into a 'submittable' string. This method will return a string
 * in the format: name1=value1&amp;name2=value2
 *
 * The semantic argument can be used to force form serialization in semantic order.
 * If your form must be submitted with name/value pairs in semantic order then pass
 * true for this arg, otherwise pass false (or nothing) to avoid the overhead for
 * this logic (which can be significant for very large forms).
 *
 * @example var data = $("#myForm").formSerialize();
 * $.ajax('POST', "myscript.cgi", data);
 * @desc Collect all the data from a form into a single string
 *
 * @name formSerialize
 * @param semantic true if serialization must maintain strict semantic ordering of elements (slower)
 * @type String
 * @cat Plugins/Form
 */
$.fn.formSerialize = function(semantic) {
    //hand off to jQuery.param for proper encoding
    return $.param(this.formToArray(semantic));
};


/**
 * Serializes all field elements in the jQuery object into a query string.
 * This method will return a string in the format: name1=value1&amp;name2=value2
 *
 * The successful argument controls whether or not serialization is limited to
 * 'successful' controls (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
 * The default value of the successful argument is true.
 *
 * @example var data = $("input").formSerialize();
 * @desc Collect the data from all successful input elements into a query string
 *
 * @example var data = $(":radio").formSerialize();
 * @desc Collect the data from all successful radio input elements into a query string
 *
 * @example var data = $("#myForm :checkbox").formSerialize();
 * @desc Collect the data from all successful checkbox input elements in myForm into a query string
 *
 * @example var data = $("#myForm :checkbox").formSerialize(false);
 * @desc Collect the data from all checkbox elements in myForm (even the unchecked ones) into a query string
 *
 * @example var data = $(":input").formSerialize();
 * @desc Collect the data from all successful input, select, textarea and button elements into a query string
 *
 * @name fieldSerialize
 * @param successful true if only successful controls should be serialized (default is true)
 * @type String
 * @cat Plugins/Form
 */
$.fn.fieldSerialize = function(successful) {
    var a = [];
    this.each(function() {
        var n = this.name;
        if (!n) return;
        var v = $.fieldValue(this, successful);
        if (v && v.constructor == Array) {
            for (var i=0,max=v.length; i < max; i++)
                a.push({name: n, value: v[i]});
        }
        else if (v !== null && typeof v != 'undefined')
            a.push({name: this.name, value: v});
    });
    //hand off to jQuery.param for proper encoding
    return $.param(a);
};


/**
 * Returns the value(s) of the element in the matched set.  For example, consider the following form:
 *
 *  <form><fieldset>
 *      <input name="A" type="text" />
 *      <input name="A" type="text" />
 *      <input name="B" type="checkbox" value="B1" />
 *      <input name="B" type="checkbox" value="B2"/>
 *      <input name="C" type="radio" value="C1" />
 *      <input name="C" type="radio" value="C2" />
 *  </fieldset></form>
 *
 *  var v = $(':text').fieldValue();
 *  // if no values are entered into the text inputs
 *  v == ['','']
 *  // if values entered into the text inputs are 'foo' and 'bar'
 *  v == ['foo','bar']
 *
 *  var v = $(':checkbox').fieldValue();
 *  // if neither checkbox is checked
 *  v === undefined
 *  // if both checkboxes are checked
 *  v == ['B1', 'B2']
 *
 *  var v = $(':radio').fieldValue();
 *  // if neither radio is checked
 *  v === undefined
 *  // if first radio is checked
 *  v == ['C1']
 *
 * The successful argument controls whether or not the field element must be 'successful'
 * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
 * The default value of the successful argument is true.  If this value is false the value(s)
 * for each element is returned.
 *
 * Note: This method *always* returns an array.  If no valid value can be determined the
 *       array will be empty, otherwise it will contain one or more values.
 *
 * @example var data = $("#myPasswordElement").fieldValue();
 * alert(data[0]);
 * @desc Alerts the current value of the myPasswordElement element
 *
 * @example var data = $("#myForm :input").fieldValue();
 * @desc Get the value(s) of the form elements in myForm
 *
 * @example var data = $("#myForm :checkbox").fieldValue();
 * @desc Get the value(s) for the successful checkbox element(s) in the jQuery object.
 *
 * @example var data = $("#mySingleSelect").fieldValue();
 * @desc Get the value(s) of the select control
 *
 * @example var data = $(':text').fieldValue();
 * @desc Get the value(s) of the text input or textarea elements
 *
 * @example var data = $("#myMultiSelect").fieldValue();
 * @desc Get the values for the select-multiple control
 *
 * @name fieldValue
 * @param Boolean successful true if only the values for successful controls should be returned (default is true)
 * @type Array<String>
 * @cat Plugins/Form
 */
$.fn.fieldValue = function(successful) {
    for (var val=[], i=0, max=this.length; i < max; i++) {
        var el = this[i];
        var v = $.fieldValue(el, successful);
        if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length))
            continue;
        v.constructor == Array ? $.merge(val, v) : val.push(v);
    }
    return val;
};

/**
 * Returns the value of the field element.
 *
 * The successful argument controls whether or not the field element must be 'successful'
 * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
 * The default value of the successful argument is true.  If the given element is not
 * successful and the successful arg is not false then the returned value will be null.
 *
 * Note: If the successful flag is true (default) but the element is not successful, the return will be null
 * Note: The value returned for a successful select-multiple element will always be an array.
 * Note: If the element has no value the return value will be undefined.
 *
 * @example var data = jQuery.fieldValue($("#myPasswordElement")[0]);
 * @desc Gets the current value of the myPasswordElement element
 *
 * @name fieldValue
 * @param Element el The DOM element for which the value will be returned
 * @param Boolean successful true if value returned must be for a successful controls (default is true)
 * @type String or Array<String> or null or undefined
 * @cat Plugins/Form
 */
$.fieldValue = function(el, successful) {
    var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
    if (typeof successful == 'undefined') successful = true;

    if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
        (t == 'checkbox' || t == 'radio') && !el.checked ||
        (t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
        tag == 'select' && el.selectedIndex == -1))
            return null;

    if (tag == 'select') {
        var index = el.selectedIndex;
        if (index < 0) return null;
        var a = [], ops = el.options;
        var one = (t == 'select-one');
        var max = (one ? index+1 : ops.length);
        for(var i=(one ? index : 0); i < max; i++) {
            var op = ops[i];
            if (op.selected) {
                // extra pain for IE...
                var v = $.browser.msie && !(op.attributes['value'].specified) ? op.text : op.value;
                if (one) return v;
                a.push(v);
            }
        }
        return a;
    }
    return el.value;
};


/**
 * Clears the form data.  Takes the following actions on the form's input fields:
 *  - input text fields will have their 'value' property set to the empty string
 *  - select elements will have their 'selectedIndex' property set to -1
 *  - checkbox and radio inputs will have their 'checked' property set to false
 *  - inputs of type submit, button, reset, and hidden will *not* be effected
 *  - button elements will *not* be effected
 *
 * @example $('form').clearForm();
 * @desc Clears all forms on the page.
 *
 * @name clearForm
 * @type jQuery
 * @cat Plugins/Form
 */
$.fn.clearForm = function() {
    return this.each(function() {
        $('input,select,textarea', this).clearFields();
    });
};

/**
 * Clears the selected form elements.  Takes the following actions on the matched elements:
 *  - input text fields will have their 'value' property set to the empty string
 *  - select elements will have their 'selectedIndex' property set to -1
 *  - checkbox and radio inputs will have their 'checked' property set to false
 *  - inputs of type submit, button, reset, and hidden will *not* be effected
 *  - button elements will *not* be effected
 *
 * @example $('.myInputs').clearFields();
 * @desc Clears all inputs with class myInputs
 *
 * @name clearFields
 * @type jQuery
 * @cat Plugins/Form
 */
$.fn.clearFields = $.fn.clearInputs = function() {
    return this.each(function() {
        var t = this.type, tag = this.tagName.toLowerCase();
        if (t == 'text' || t == 'password' || tag == 'textarea')
            this.value = '';
        else if (t == 'checkbox' || t == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = -1;
    });
};


/**
 * Resets the form data.  Causes all form elements to be reset to their original value.
 *
 * @example $('form').resetForm();
 * @desc Resets all forms on the page.
 *
 * @name resetForm
 * @type jQuery
 * @cat Plugins/Form
 */
$.fn.resetForm = function() {
    return this.each(function() {
        // guard against an input with the name of 'reset'
        // note that IE reports the reset function as an 'object'
        if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType))
            this.reset();
    });
};


/**
 * Enables or disables any matching elements.
 *
 * @example $(':radio').enabled(false);
 * @desc Disables all radio buttons
 *
 * @name select
 * @type jQuery
 * @cat Plugins/Form
 */
$.fn.enable = function(b) { 
    if (b == undefined) b = true;
    return this.each(function() { 
        this.disabled = !b 
    });
};

/**
 * Checks/unchecks any matching checkboxes or radio buttons and
 * selects/deselects and matching option elements.
 *
 * @example $(':checkbox').selected();
 * @desc Checks all checkboxes
 *
 * @name select
 * @type jQuery
 * @cat Plugins/Form
 */
$.fn.select = function(select) {
    if (select == undefined) select = true;
    return this.each(function() { 
        var t = this.type;
        if (t == 'checkbox' || t == 'radio')
            this.checked = select;
        else if (this.tagName.toLowerCase() == 'option') {
            var $sel = $(this).parent('select');
            if (select && $sel[0] && $sel[0].type == 'select-one') {
                // deselect all other options
                $sel.find('option').select(false);
            }
            this.selected = select;
        }
    });
};

})(jQuery);
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('2C.2Z.3v=1k(a){M b={17:{R:8},19:{R:8},1h:{R:8},1m:{R:8},1Y:1T,2e:1T,3r:["3m"]};N(a&&3h(a)!=\'3e\')2C.37(b,a);1l 7.2N(1k(){1U 2l(b,7).2k()})};1k 2l(){7.X=2h[1];7.P=2h[0];7.1o=1W;7.1p=1W;7.23=1U 21();7.2t=1W;M G=$(7.X).O("1j");M H=$(7.X).O("1O");M I=$(7.X).O("33");M J=$(7.X).O("2m");M K=$(7.X).O("V");M L=$(7.X).O("2J");7.1G=26($(7.X).O("2D"));7.1I=26($(7.X).O("2j"));7.1R=Z(((G!=""&&G!="1X"&&G.1r("%")==-1)?G.1q(0,G.1r("T")):7.X.3t));7.2f=Z(((H!=""&&H!="1X"&&H.1r("%")==-1)?H.1q(0,H.1r("T")):7.X.3s));7.S=Z(((I!=""&&I.1r("T")!==-1)?I.2A(0,I.1r("T")):0));7.1y=Z(((L!=""&&L.1r("T")!==-1)?L.2A(0,L.1r("T")):0));7.1g=7.S+"T"+" 3q "+7.1G;7.1x=((J!="3o")?J:"");7.2v=7.X.2d;N(K!="1i")$(7.X).O("V","22");$(7.X).O("1w","1s !3i");N(($.2b.2r&&$.2b.3g==6)&&H=="1X"&&G=="1X")$(7.X).O("1O","1a%");N(($.2b.2r)){$(7.X).O("2o","1");$(7.X+" *").O("2o","3c")}N(7.P.2e==1T&&7.1y>0)7.X.2d="";7.2k=1k(){1M(M t=0;t<2;t++){1C(t){U 0:N(7.P.17||7.P.19){M a=1D.1H("1E");M b=Q.1V(7.P.17?7.P.17.R:0,7.P.19?7.P.19.R:0);$(a).O({1O:"1a%","1P-1L":"1B",1K:"1N",V:"1i","1w-W":7.S,"1w-1b":7.S,1j:b+"T",1n:0-b+"T",W:0-7.S+"T"});7.1o=7.X.18(a)};Y;U 1:N(7.P.1h||7.P.1m){M a=1D.1H("1E");M c=Q.1V(7.P.1h?7.P.1h.R:0,7.P.1m?7.P.1m.R:0);$(a).O({1O:"1a%","1P-1L":"1B",1K:"1N",V:"1i","1w-W":7.S,"1w-1b":7.S,1j:c,1t:0-c+"T",W:0-7.S+"T"});7.1p=7.X.18(a)};Y}};N(7.1o)$(7.X).O("1c-1n",0);N(7.1p)$(7.X).O("1c-1t",0);M d=["19","17","1m","1h"];1M(M i 25 d){N(i>-1<4){M e=d[i];N(!7.P[e]){N(((e=="19"||e=="17")&&7.1o!=1W)||((e=="1m"||e=="1h")&&7.1p!=1W)){M f=1D.1H("1E");$(f).O({V:"22","1P-1L":"1B",1K:"1N"});N(7.1x=="")$(f).O("2j",7.1I);1f $(f).O("2m",7.1x);1C(e){U"17":$(f).O({1j:b-7.S,"1A-1b":7.P.19.R-(7.S*2),"1c-W":7.1g,"1c-1n":7.1g,W:-7.S+"T"});Y;U"19":$(f).O({1j:b-7.S,"1A-W":7.P.17.R-(7.S*2),"1c-1b":7.1g,"1c-1n":7.1g,W:7.S+"T","1e-V":"-"+(b+7.S)+"T 1s"});Y;U"1h":$(f).O({1j:c-7.S,"1A-1b":7.P.1m.R-(7.S*2),"1c-W":7.1g,"1c-1t":7.1g,W:-7.S+"T","1e-V":"-"+(7.S)+"T -"+(7.1R+(c+7.S))+"T"});Y;U"1m":$(f).O({1j:c-7.S,"1A-W":7.P.1h.R-(7.S*2),"1c-1b":7.1g,"1c-1t":7.1g,W:7.S+"T","1e-V":"-"+(c+7.S)+"T -"+(7.1R+(c+7.S))+"T"});Y}}}1f{N(7.23[7.P[e].R]){M f=7.23[7.P[e].R].2i(1T)}1f{M f=1D.1H("1E");$(f).O({1j:7.P[e].R,1O:7.P[e].R,V:"1i","1P-1L":"1B",1K:"1N"});M g=Z(7.P[e].R-7.S);1M(M h=0,j=7.P[e].R;h<j;h++){N((h+1)>=g)M l=-1;1f M l=(Q.2g(Q.1z(Q.1d(g,2)-Q.1d((h+1),2)))-1);N(g!=j){N((h)>=g)M m=-1;1f M m=Q.2B(Q.1z(Q.1d(g,2)-Q.1d(h,2)));N((h+1)>=j)M n=-1;1f M n=(Q.2g(Q.1z(Q.1d(j,2)-Q.1d((h+1),2)))-1)};N((h)>=j)M o=-1;1f M o=Q.2B(Q.1z(Q.1d(j,2)-Q.1d(h,2)));N(l>-1)7.1F(h,0,7.1I,1a,(l+1),f,-1,7.P[e].R);N(g!=j){1M(M p=(l+1);p<m;p++){N(7.P.1Y){N(7.1x!=""){M q=(24(h,p,g)*1a);N(q<30){7.1F(h,p,7.1G,1a,1,f,0,7.P[e].R)}1f{7.1F(h,p,7.1G,1a,1,f,-1,7.P[e].R)}}1f{M r=2z(7.1I,7.1G,24(h,p,g));7.1F(h,p,r,1a,1,f,0,7.P[e].R,e)}}};N(7.P.1Y){N(n>=m){N(m==-1)m=0;7.1F(h,m,7.1G,1a,(n-m+1),f,0,0)}}1f{N(n>=l){7.1F(h,(l+1),7.1G,1a,(n-l),f,0,0)}};M s=7.1G}1f{M s=7.1I;M n=l};N(7.P.1Y){1M(M p=(n+1);p<o;p++){7.1F(h,p,s,(24(h,p,j)*1a),1,f,((7.S>0)?0:-1),7.P[e].R)}}};7.23[7.P[e].R]=f.2i(1T)};N(e!="1m"){1M(M t=0,k=f.2y.2x;t<k;t++){M u=f.2y[t];M v=Z(u.1u.1n.1q(0,u.1u.1n.1r("T")));M w=Z(u.1u.W.1q(0,u.1u.W.1r("T")));M x=Z(u.1u.1j.1q(0,u.1u.1j.1r("T")));N(e=="17"||e=="1h"){$(u).O("W",7.P[e].R-w-1+"T")};N(e=="19"||e=="17"){$(u).O("1n",7.P[e].R-x-v+"T")};1C(e){U"19":$(u).O("1e-V","-"+Q.1v((7.2f-7.P[e].R+7.S)+w)+"T -"+Q.1v(7.P[e].R-x-v-7.S)+"T");Y;U"17":$(u).O("1e-V","-"+Q.1v((7.P[e].R-w-1)-7.S)+"T -"+Q.1v(7.P[e].R-x-v-7.S)+"T");Y;U"1h":$(u).O("1e-V","-"+Q.1v((7.P[e].R-w-1)-7.S)+"T -"+Q.1v((7.1R+7.P[e].R+v)-7.S)+"T");Y}}}};N(f){1C(e){U"17":N($(f).O("V")=="1i")$(f).O("1n","0");N($(f).O("V")=="1i")$(f).O("W","0");N(7.1o)7.1o.18(f);Y;U"19":N($(f).O("V")=="1i")$(f).O("1n","0");N($(f).O("V")=="1i")$(f).O("1b","0");N(7.1o)7.1o.18(f);Y;U"1h":N($(f).O("V")=="1i")$(f).O("1t","0");N(f.1u.V=="1i")$(f).O("W","0");N(7.1p)7.1p.18(f);Y;U"1m":N($(f).O("V")=="1i")$(f).O("1t","0");N($(f).O("V")=="1i")$(f).O("1b","0");N(7.1p)7.1p.18(f);Y}}}};M y=1U 21();y["t"]=Q.1v(7.P.17.R-7.P.19.R);y["b"]=Q.1v(7.P.1h.R-7.P.1m.R);1M(z 25 y){N(z=="t"||z=="b"){N(y[z]){M A=((7.P[z+"l"].R<7.P[z+"r"].R)?z+"l":z+"r");M B=1D.1H("1E");$(B).O({1j:y[z],1O:7.P[A].R+"T",V:"1i","1P-1L":"1B",1K:"1N","1e-2c":7.1I});1C(A){U"17":$(B).O({1t:"1s",W:"1s","1c-1b":7.1g});7.1o.18(B);Y;U"19":$(B).O({1t:"1s",1b:"1s","1c-1b":7.1g});7.1o.18(B);Y;U"1h":$(B).O({1n:"1s",W:"1s","1c-W":7.1g});7.1p.18(B);Y;U"1m":$(B).O({1t:"1s",1b:"1s","1c-1b":7.1g});7.1p.18(B);Y}};M C=1D.1H("1E");$(C).O({V:"22","1P-1L":"1B",1K:"1N","1e-2c":7.1I,"1e-2u":7.1x});1C(z){U"t":N(7.1o){N(7.P.17.R&&7.P.19.R){$(C).O({1j:b-7.S,"1A-W":7.P.17.R-7.S,"1A-1b":7.P.19.R-7.S,"1c-1n":7.1g});7.1o.18(C);N(7.1x!="")$(C).O("1e-V","-"+(b+7.S)+"T 1s");7.1o.18(C)};$(7.X).O("1e-V","1s -"+(b-7.S)+"T")};Y;U"b":N(7.1p){N(7.P.1h.R&&7.P.1m.R){$(C).O({1j:c-7.S+"T","1A-W":7.P.1h.R-7.S,"1A-1b":7.P.1m.R-7.S,"1c-1t":7.1g});7.1p.18(C);N(7.1x!="")$(C).O("1e-V","-"+(c+7.S)+"T -"+(7.1R+(b+7.S))+"T");7.1p.18(C)}};Y}}};N(7.P.2e==1T&&7.1y>0){M D=1D.1H("1E");$(D).O("V","22");D.2d=7.2v;$(D).3l="3k";M E=Q.1v(b-7.1y);M F=Q.1v(c-7.1y);N(b<7.1y)$(D).O("1w-1n",E);N(c<7.1y)$(D).O("1w-1t",c);$(D).O({"1w-W":7.1y,"1w-1b":7.1y});7.2t=7.X.18(D)}};7.1F=1k(a,b,c,d,e,f,g,h){M i=1D.1H("1E");$(i).O({1j:e,1O:"1B",V:"1i","1P-1L":"1B",1K:"1N"});M j=Q.1V(7.P["19"].R,7.P["17"].R);N(g==-1&&7.1x!=""){$(i).O({"1e-2u":7.1x,"1e-V":((7.2f-(h-a)+7.S)*-1)+"T "+(((7.1R+j+b)-7.S)*-1)+"T"})}1f{$(i).O("1e-2c",c)};N(d!=1a)2s(i,d);$(i).O({1n:b+"T",W:a+"T"});f.18(i)}};1k 2z(a,b,c){M d=Z(a.1Q(1,2),16);M e=Z(a.1Q(3,2),16);M f=Z(a.1Q(5,2),16);M g=Z(b.1Q(1,2),16);M h=Z(b.1Q(3,2),16);M i=Z(b.1Q(5,2),16);N(c>1||c<0)c=1;M j=Q.27((d*c)+(g*(1-c)));N(j>1S)j=1S;N(j<0)j=0;M k=Q.27((e*c)+(h*(1-c)));N(k>1S)k=1S;N(k<0)k=0;M l=Q.27((f*c)+(i*(1-c)));N(l>1S)l=1S;N(l<0)l=0;1l"#"+1J(j)+1J(k)+1J(l)};1k 1J(a){20=a/16;2a=a%16;20=20-(2a/16);2q=29(20);2p=29(2a);1l 2q+\'\'+2p};1k 29(x){N((x>=0)&&(x<=9)){1l x}1f{1C(x){U 10:1l"A";U 11:1l"B";U 12:1l"C";U 13:1l"D";U 14:1l"E";U 15:1l"F"}}};1k 24(x,y,r){M a=0;M b=1U 21(1);M c=1U 21(1);M d=0;M e="";M f=Q.1z((Q.1d(r,2)-Q.1d(x,2)));N((f>=y)&&(f<(y+1))){e="3a";b[d]=0;c[d]=f-y;d=d+1};M f=Q.1z((Q.1d(r,2)-Q.1d(y+1,2)));N((f>=x)&&(f<(x+1))){e=e+"38";b[d]=f-x;c[d]=1;d=d+1};M f=Q.1z((Q.1d(r,2)-Q.1d(x+1,2)));N((f>=y)&&(f<(y+1))){e=e+"36";b[d]=1;c[d]=f-y;d=d+1};M f=Q.1z((Q.1d(r,2)-Q.1d(y,2)));N((f>=x)&&(f<(x+1))){e=e+"35";b[d]=f-x;c[d]=0};1C(e){U"34":a=Q.1Z(c[0],c[1])+((Q.1V(c[0],c[1])-Q.1Z(c[0],c[1]))/2);Y;U"32":a=1-(((1-b[0])*(1-c[1]))/2);Y;U"39":a=Q.1Z(b[0],b[1])+((Q.1V(b[0],b[1])-Q.1Z(b[0],b[1]))/2);Y;U"31":a=(c[0]*b[1])/2;Y;3b:a=1};1l a};1k 28(a){2Y{M b=2n(a);M c=Z(b[0]);M d=Z(b[1]);M f=Z(b[2]);M g="#"+1J(c)+1J(d)+1J(f)}2X(e){2W("2V 2U 3d 2T 2S 2R 3f 2Q 2P 2O 25 1k 28")};1l g};1k 2n(a){M b=a.1q(4,a.1r(")"));M c=b.3j(", ");1l c};1k 2s(a,b){b=(b==1a)?2M.2L:b;a.1u.2K="3n:2I.3p.2H(2w="+b+");";a.1u.2G=b/1a;a.1u.2F=b/1a;a.1u.2w=b/1a};1k 26(a){M b="#2E";N(a!=""&&a!="3u"){N(a.1Q(0,3)=="3w"){b=28(a)}1f N(a.2x==4){b="#"+a.1q(1,2)+a.1q(1,2)+a.1q(2,3)+a.1q(2,3)+a.1q(3,4)+a.1q(3,4)}1f{b=a}};1l b};',62,219,'|||||||this|||||||||||||||||||||||||||||||||||||||||var|if|css|settings|Math|radius|borderWidth|px|case|position|left|box|break|parseInt||||||||tl|appendChild|tr|100|right|border|pow|background|else|borderString|bl|absolute|height|function|return|br|top|topContainer|bottomContainer|substring|indexOf|0px|bottom|style|abs|padding|bgImage|boxPadding|sqrt|margin|1px|switch|document|DIV|drawPixel|borderColour|createElement|boxColour|IntToHex|overflow|size|for|hidden|width|font|substr|boxHeight|255|true|new|max|null|auto|antiAlias|min|base|Array|relative|masterCorners|pixelFraction|in|format_colour|round|rgb2Hex|MakeHex|rem|browser|color|innerHTML|autoPad|boxWidth|floor|arguments|cloneNode|backgroundColor|applyCorners|curvyObject|backgroundImage|rgb2Array|zoom|remS|baseS|msie|setOpacity|contentDIV|image|boxContent|opacity|length|childNodes|BlendColour|slice|ceil|jQuery|borderTopColor|ffffff|MozOpacity|KHTMLOpacity|Alpha|DXImageTransform|paddingTop|filter|999|99|each|Hexadecimal|to|value|the|converting|error|was|There|alert|catch|try|fn||LeftBottom|TopRight|borderTopWidth|LeftRight|Bottom|Right|extend|Top|TopBottom|Left|default|normal|an|string|RGB|version|typeof|important|split|autoPadDiv|addClass|div|progid|none|Microsoft|solid|validTags|scrollWidth|scrollHeight|transparent|corner|rgb'.split('|'),0,{}))
